package com.pwc.testing;

import java.util.Set;

import org.openqa.selenium.WebDriver;

public class SeleniumSystem implements ISeleniumSystem {

	private WebDriver driver;
	private LogUtil log;

	public SeleniumSystem(WebDriver driver, LogUtil log) {
		this.driver = driver;
		this.log = log;
	}

	public void get(String path) {
		driver.get(path);
		log.addLog("get web page:" + path);
	}

	public void quit() {
		driver.quit();
		log.addLog("quit system...");
	}

	public void sleep(long t) throws InterruptedException {
		Thread.sleep(t);
		log.addLog("wait:" + t + "ms");
	}

	public void back() {
		driver.navigate().back();
		log.addLog("browser go back");
	}

	public void forward() {
		driver.navigate().forward();
		log.addLog("browser go forward");
	}

	public void close() {
		driver.close();
		log.addLog("close current page");
	}
	
	
	public void switchToWindow(String tabNumber) {

		Set<String> newTabInstance = driver.getWindowHandles(); 

		String newWindow = newTabInstance.toArray()[Integer.parseInt(tabNumber)].toString();

		driver.switchTo().window(newWindow);

		log.addLog("switch to tab " + tabNumber);
	}

}
